<script>
import {data} from "autoprefixer";
import {id} from "html-webpack-plugin/lib/chunksorter";

export default {
  data(){
    return{
      hotel:[{
        hotelId:''
      }],
      pageable:{
        currentpage:1,
        pagesizes:[5,10,15,20],
        pagesize:5,
        total:''

      },
    }
  },
  mounted() {
    this.findAll()
  },
  methods:{
    del(row) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(()=>{
        this.$axios.get('AdminHotel/del',{
          params:{
            hid:row.hotelId
          }
        }).then(data=>{
          if (data.data.code==200){
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.findAll()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    handleSizeChange(val) {
     this.pageable.pagesize=val
      this.findAll()
    },
    handleCurrentChange(val) {
      this.pageable.currentpage=val
      this.findAll()
    },
    findAll(){
      this.$axios.get('AdminHotel/findAllHotel',{
        params:{
          page:this.pageable.currentpage,
          limit:this.pageable.pagesize
        },
      }).then(data=>{
       console.log(data.data.data.records)
        this.hotel=data.data.data.records
        this.pageable.total=data.data.data.total
      })

    },
    updata(cityId,hotelId){
      this.$router.push({path:'/updatehotel',query:{cityId:cityId,hotelId:hotelId}})
    },
  }
}
</script>
<template>
  <div>
    <el-table
      :data="hotel"
      style="width: 100%">
      <el-table-column
        prop="hotelName"
        label="酒店名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="hotelPrice"
        label="酒店价格">
      </el-table-column>
      <el-table-column
        prop="hotelScore"
        label="酒店评分">
      </el-table-column>
      <el-table-column
        prop="cityName"
        label="所属城市">
      </el-table-column>
      <el-table-column
        prop="hotelInfo"
        label="酒店信息">
      </el-table-column>
      <el-table-column
        label="酒店图片">
        <template slot-scope="scope">
          <el-image
            style="width: 100px; height: 100px"
            :src="scope.row.hotelPic"
            fit="fill"></el-image>
        </template>
      </el-table-column>
      <el-table-column
        prop="hotelLebgth"
        label="酒店距离">
      </el-table-column>
      <el-table-column
        prop="hotelComment"
        label="酒店描述">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="100">
        <template slot-scope="scope">
          <el-button  @click="updata(scope.row.cityId,scope.row.hotelId)" type="success" size="small">查看</el-button><br>
          <el-button @click="del(scope.row)" type="primary" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page=pageable.currentpage
      :page-sizes=pageable.pagesizes
      :page-size=pageable.pagesize
      layout="total, sizes, prev, pager, next, jumper"
      :total=pageable.total
    >
    </el-pagination>
  </div>


</template>

<style >
</style>
